package com.highspeed.bdk.gateway.socket.analyze.message.preset_deploy.base;

import com.highspeed.bdk.gateway.Util;
import com.highspeed.bdk.gateway.socket.analyze.base.AbstractResolver;

import java.util.Map;

public abstract class MessageResolver extends AbstractResolver {
    @Override
    protected Map doResolveHeader(byte[] response) {
        //帧头
        int frameHead = Util.getInt(response, getOffset());
        offset4();
        logger.info("帧头.........." + frameHead);

        //消息长度
        int length = Util.getInt(response, getOffset());
        offset4();
        logger.info("消息长度.........." + length);

        //源逻辑ID
        short srcLogicalId = Util.getShort(response, getOffset());
        offset2();
        logger.info("源逻辑ID.........." + srcLogicalId);

        //目的逻辑ID
        short destLogicalId = Util.getShort(response, getOffset());
        offset2();
        logger.info("目的逻辑ID.........." + destLogicalId);

        //消息类型
        byte messageType = Util.getByte(response, getOffset());
        offset1();
        logger.info("消息类型.........." + messageType);

        //消息类别  F0
        int classic = Util.getUnsignedByte(response, getOffset());
        offset1();
        logger.info("消息类别.........." + classic);

        //消息ID
        short messageId = Util.getShort(response, getOffset());
        offset2();
        logger.info("消息ID.........." + messageId);

        //消息发送时间
        long mills = Util.getInt(response, getOffset());
        offset4();
        logger.info("消息发送时间..........毫秒数...." + mills);
        long naos = Util.getInt(response, getOffset());
        offset4();
        logger.info("消息发送时间..........纳秒数" + naos);


        //消息发送序号
        short seq = Util.getShort(response, getOffset());
        offset2();
        logger.info("消息发送序号.........." + seq);

        //保留
        short reserved = 0;
        offsetN(6);
        logger.info("保留.........." + reserved);

        //命令编号 暂时不填
        offsetN(20);
        logger.info("命令编号.........." + 0);

        //RIO模块MARK地址
        short markAddr = Util.getShort(response, getOffset());
        offset2();
        logger.info("RIO模块MARK地址.........." + markAddr);

        //类型
        short type = Util.getShort(response, getOffset());
        offset2();
        logger.info("类型.........." + type);

        //编号
        short no = Util.getShort(response, getOffset());
        offset2();
        logger.info("编号.........." + no);

        //版本
        String version = "";
        version += Util.byteToString(response, getOffset());
        offset1();
        version += Util.byteToString(response, getOffset());
        offset1();
        version += Util.byteToString(response, getOffset());
        offset1();
        logger.info("版本.........." + version);

        //保留
        byte reserved1 = Util.getByte(response, getOffset());
        offset1();
        logger.info("保留.........." + reserved1);

        //固话时间
        String time = "";
        time += Util.byteToString(response, getOffset());
        offset1();
        time += Util.byteToString(response, getOffset());
        offset1();
        time += "-" + Util.byteToString(response, getOffset());
        offset1();
        time += "-" + Util.byteToString(response, getOffset());
        offset1();
        time += ":" + Util.byteToString(response, getOffset());
        offset1();
        time += ":" + Util.byteToString(response, getOffset());
        offset1();
        time += ":" + Util.byteToString(response, getOffset());
        offset1();
        logger.info("固话时间.........." + time);

        //保留
        byte reserved2 = Util.getByte(response, getOffset());
        offset1();
        logger.info("保留.........." + reserved2);
        return getContainer();
    }

    @Override
    protected Map doResolveTail(byte[] response) {
        return getContainer();
    }

}
